package tutorial.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;

import tutorial.entity.FacilityEntity;
import tutorial.form.FacilityForm;
import tutorial.service.FacilityService;

public class FacilityDetailAction {
    
    @Resource
    protected HttpSession session;

    public FacilityEntity facilityEntity;

    //public List<Map<String, String>> facilityItems;

    @ActionForm
    @Resource
    protected FacilityForm facilityForm;

    @Resource
    protected FacilityService facilityService;

    @Execute(validator = false)
    public String index() {
        List<Map<String, String>> facilityItems = facilityService.findAllFacilityNo();
        session.setAttribute("facilityItems", facilityItems);
        
        System.out.println("Test");
        System.out.println("Test2");
        System.out.println("Test3");
        
        if (facilityItems.size() > 0) {
            Map<String, String> facilityNoMap = facilityItems.get(0);
            String facilityNo = facilityNoMap.get("value");
            facilityForm.facilityNo = facilityNo;
            facilityEntity = facilityService.findFacility(facilityNo);
        }
        return "detail.jsp";
    }
    
    @Execute(validator = false)
    public String changeFacility() {
        String facilityNo = facilityForm.getFacilityNo();
        facilityEntity = facilityService.findFacility(facilityNo);
        return "detail.jsp";
    }

    @Execute(input = "photo.jsp")
    public String gotoPhoto() {
        return "photo.jsp";
    }
}